//
//  productdetailsView.m
//  HJB_project
//
//  Created by panquanReabam.com on 15-5-27.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.
//

#import "productdetailsView.h"
#import "BigImages.h"
#import "HAODEsingleton.h"
@interface productdetailsView ()

{
    UIScrollView *mainScroll;
    UILabel *labelNumber;
    UILabel *labelDetail;
   
    UIView *backView;
    UIView *viewBottom;
    UIScrollView *imageScroll;
    
    
}
@property (nonatomic , assign) NSInteger currentPageIndex;
@property (nonatomic , assign) NSInteger totalPageCount;
@end

@implementation productdetailsView
{
    HAODEsingleton* commdity;}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
         commdity=[HAODEsingleton shared];
        mainScroll = [[UIScrollView alloc]initWithFrame:self.bounds];
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:mainScroll];
        
        //滚动图片
        imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 370)];
        [mainScroll addSubview:imageScroll];
        
        imageScroll.contentSize = CGSizeMake(ScreenWidth * _arrayImage.count, 370);
        imageScroll.pagingEnabled = YES;
        imageScroll.delegate = self;
        imageScroll.showsHorizontalScrollIndicator = NO;
     
        
        self.page = [[UIPageControl alloc]initWithFrame:CGRectZero];
        self.page.frame = CGRectMake(0,350, self.bounds.size.width, 20);
        self.page.currentPageIndicatorTintColor=titleColor;
        self.page.pageIndicatorTintColor=zuiqianhuicolor;
        self.page.numberOfPages =commdity.hows.count;
        self.page.currentPage = 0;
        
        [mainScroll addSubview:self.page];
        
        labelNumber = [[UILabel alloc]initWithFrame:CGRectZero];
        labelNumber.text = [NSString stringWithFormat:@"%d/%lu",1,(unsigned long)_arrayImage.count];
        labelNumber.font = [UIFont systemFontOfSize:14];
        labelNumber.textColor = [UIColor grayColor];
        [labelNumber sizeToFit];
        labelNumber.origin = CGPointMake(ScreenWidth - labelNumber.width - 10, 10);
        [mainScroll addSubview:labelNumber];
        
        
        
        _erweimaImageview=[[UIButton alloc]initWithFrame:CGRectMake(10, imageScroll.bottom+1, 30, 30)];
        [_erweimaImageview setImage:[UIImage imageNamed:@"erweimaxiangqing"] forState:UIControlStateNormal];
        [mainScroll addSubview:_erweimaImageview];
        
        _itemCode = [[UILabel alloc]initWithFrame:CGRectMake(_erweimaImageview.right+5, imageScroll.bottom+10, 250, 14)];
        _itemCode.textColor = [UIColor grayColor];
        _itemCode.font = [UIFont systemFontOfSize:14];
        [mainScroll addSubview:_itemCode];
        
        
        _itemName = [[UILabel alloc]initWithFrame:CGRectMake(15, 410, 260, 17)];
        _itemName.textColor = [UIColor blackColor];
        _itemName.font = [UIFont systemFontOfSize:17];
        [mainScroll addSubview:_itemName];
       
        _saleQty = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-150, imageScroll.bottom+10, 130, 13)];
        _saleQty.textColor = zhonghuiColor;
        _saleQty.textAlignment=NSTextAlignmentRight;
        _saleQty.font = [UIFont systemFontOfSize:13];
        [mainScroll addSubview:_saleQty];
        

        
        mainScroll.contentSize = CGSizeMake(ScreenWidth, 450);
        
    }
    return self;
}

- (void)setArrayImage:(NSArray *)arrayImage
{

    _arrayImage = arrayImage;
    for (int i=0; i<_arrayImage.count; i++) {
        BigImages *imageVC = [[BigImages alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, 370)];
               [imageVC setImageWithURL:[NSURL URLWithString:_arrayImage[i]] placeholderImage:[UIImage imageNamed:@"home.png"]];
//       [imageVC getBigImage:_arrayImage[i]];
//        imageVC.frame = CGRectMake(200*i, 0, 200, 220);
        [imageScroll addSubview:imageVC];
    }
    imageScroll.contentSize = CGSizeMake(ScreenWidth * _arrayImage.count, 370);
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",1,(unsigned long)_arrayImage.count];
      NSLog(@"------%lu",(unsigned long)_arrayImage.count);
}



#pragma mark -
#pragma mark - UIScrollViewDelegate



- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
        self.page.currentPage = round(scrollView.contentOffset.x / scrollView.frame.size.width);
  
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    
    self.page.currentPage = round(scrollView.contentOffset.x / scrollView.frame.size.width);
    NSLog(@"%ld",self.page.currentPage);

    
    labelNumber.text = [NSString stringWithFormat:@"%ld/%lu",self.page.currentPage+1,(unsigned long)_arrayImage.count];
}



@end
